<template>
  <div class="list2">
    <header class="head">
      <span class="titletop" @click="isoka = !isoka">
        {{title}}
        <img src="../img/h_ico.png" class="h-ico" />
      </span>
      <div class="lever" v-show="isoka">
        <div
          v-for="(item,index) in this.list"
          :key="item.id"
          :class="{current:item.isok}"
          @click="selected(item.name,index)"
        >
          <img src="../img/arrow.png" alt />
          {{item.name}}
        </div>
      </div>
      <section class="sortbar border-1px">
        <!--浮动增加样式“sortbarFixedTop”-->
        <div class="instock">
          筛选
          <span></span>
        </div>
        <div class="sortMain clearfix">
          <div class="o-complex">综合</div>
          <div class="o-sales">销量</div>
          <div class="o-news">新品</div>
          <div class="o-price">
            价格
            <span></span>
          </div>
        </div>
        <div class="clearfix"></div>
      </section>
    </header>
    <!-- 列表2  -->
    <div class="mainlist">
      <div class="items" v-for="item in this.list2" :key="item.id" @click="details(item)">
        <figure style="height: 180px;">
          <img
            class="goodsImg lazy"
            :data-original="item.img"
            :src="item.img"
            style="display: inline;"
          />
        </figure>
        <div class="items-x">
          <p class="name">{{item.name}}</p>
          <p class="dis">{{item.dis}}</p>
          <p>
            <span class="salePrice">{{item.delprice}}</span>
            <span class="price">{{item.price}}</span>
          </p>
        </div>
      </div>
    </div>
    <!--  -->
  </div>
</template>
<script>
export default {
  data() {
    return {
      title: this.$route.query.name,
      isoka: false,
      list: [],
      list2: ""
    };
  },
  methods: {
    async getdata2(cname) {
      let { data } = await this.$axios.get(
        "http://localhost:5555/listbo/list3",
        {
          params: { cname }
        }
      );
      this.list2 = data;
      // console.log(this.list2);
    },
    async getdata() {
      //发送请求渲染顶部分类
      let { data } = await this.$axios.get(
        "http://localhost:5555/listbo/list2",
        {
          params: this.$route.query
        }
      );
      this.list = data;
      this.getdata2(this.title);
    },

    selected(title, index) {
      //点击切换顶部分类名字
      this.list[index].isok = this.list[index].isok; //点击分类选中打勾✔ ，暂时有bug不启用该功能，若启用，= 后面加个！  取反
      this.isoka = !this.isoka;
      this.title = title;
      this.getdata2(this.title);
    },
    details(item) {
      //点击商品进入详情页
      
      
      let { id, cname, img, name, dis, price, delprice ,isok2} = item;
      // window.console.log({ id, cname, img, name, dis, price, delprice });
      this.$router.push({ name: "details", query: { id, cname, img, name, dis, price, delprice, isok2}
      });
    }
  },
  created() {
    //页面加载完成就调用发送请求
    this.getdata();
  }
};
</script>
<style scopde>
.mainlist {
  background: #f1f1f1;
  overflow: hidden;
  margin-top: 2rem;
}
header {
  width: 100%;
  height: 1.9rem;
  background: #fafafa;
  font-size: 18px;
  position: fixed;
  top: 0;
  z-index: 2;
}
.titletop {
  font-size: 17px;
  margin: auto;
}
.h-ico {
  height: 9px;
  width: 9px;
  margin-top: 8px;
  margin-left: 3px;
}
.lever {
  position: fixed;
  top: 30px;
  left: 0;
  width: 100%;
  background-color: #fff;
  z-index: 13;
  padding: 5px 0;
}
.lever > div {
  float: left;
  width: 47%;
  font-size: 14px;
  text-align: center;
  line-height: 2.8em;
  color: #272727;
}
.lever > div img {
  height: 0.8em;
  width: auto;
  margin-top: 0.9em;
  margin-right: 5px;
  visibility: hidden;
}
.lever > div .current {
  color: #c4193f;
}
.lever .current img {
  visibility: visible;
}
/* 排序 */
.sortbar {
  position: relative;
  width: 100%;
  height: 40px;
  line-height: 40px;
  text-align: center;
  color: #333333;
  font-size: 14px;
  border-top: #ebebeb solid 1px;
  background: white;
  /* font-size: 0.93em; */
}
.instock {
  width: 25%;
  float: right;
}
.instock span {
  display: inline-block;
  width: 1.5em;
  height: 0.8em;
  /* background: url(../../images/class/goods-list/sy.png) no-repeat; */
  background-size: auto 100%;
}
.sortMain {
  width: 75%;
  position: relative;
  float: left;
}
.sortMain > div {
  width: 25%;
  float: left;
}
.o-price span {
  width: 0.8em;
  height: 0.8em;
  /* background: url(../../images/class/goods-list/def.png) center center no-repeat; */
  background-size: auto 100%;
  padding-top: 3px;
}

/* 列表2 */
.items {
  width: 48%;
  margin-left: 1.5%;
  float: left;
  background-color: #fff;
  margin-bottom: 6px;
}
.items figure {
  width: 100%;
  overflow: hidden;
  position: relative;
}
.items figure .goodsImg {
  width: 100%;
}
.items-x .name {
  color: #323232;
  height: 1em;
  line-height: 1em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  float: left;
  margin-top: 0.2rem;
}
.items-x .dis {
  line-height: 1.3em;
  height: 2.6em;
  margin: 5px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  color: #787878;
  font-size: 14px;
  float: left;
  text-align: left;
}
.salePrice {
  color: #c4193f;
  font-size: 16px;
  float: left;
}
.price {
  color: #959595;
  margin-left: 5px;
  font-size: 16px;
  text-decoration: line-through;
  float: left;
}
</style>